var url="";
var model;
var request;
var Shebei;
var result=false;
function LoadData(){
    request.post('http://'+url+'/app/DeviceState!ajaxDeviceState?projectId='+GetQueryString('projectId')).success(function(data){
        console.log(data);
        Shebei.initImg(data);
        result=true;
         }).error(function(data,status,headers,config){
      if((status>=200&&status<300)||status===304||status===1223||status===0){
      $("body").html("网络访问出错！");
      }
      });
}

(function(){
	var app=angular.module('Shebei',[ ]);
	app.controller('ShebeiController',['$http','$window',function($http,$window){
        Shebei=this;
		request=$http;
        url = '120.26.110.125/jncloud';
        Shebei.url = url;
        Shebei.projectId = GetQueryString('projectId');
        Shebei.ta = new Array();
        Shebei.reji =new Array();
        Shebei.lengdong=new Array();
        Shebei.lengque=new Array();
        bindEvent();
        LoadData();

        Shebei.initImg=function(data){
            if(data!=null)
            {
                for(var i=0;i<data.cooling_tower_state.length;i++)
                {
                     var obj = new Object();
                     if(data.cooling_tower_state[i].state=="1")
                     {
                         obj.img = 'lengqueta1.png';
                     }else if(data.cooling_tower_state[i].state=="-1")
                     {
                         obj.img = 'lengqueta2.png';
                     }else if(data.cooling_tower_state[i].state=="0")
                     {
                        obj.img = 'lengqueta3.png';
                     }
                     obj.id=data.cooling_tower_state[i].object_id;
                     Shebei.ta.push(obj);
                }

               for(var i=0;i<data.chilled_water_pump_state.length;i++)
                {
                    var obj = new Object();
                     if(data.chilled_water_pump_state[i].state=="1")
                     {
                         obj.img = 'lengdongshui1.png';
                     }else if(data.chilled_water_pump_state[i].state=="-1")
                     {
                         obj.img = 'lengdongshui2.png';
                     }else if(data.chilled_water_pump_state[i].state=="0")
                     {
                        obj.img = 'lengdongshui3.png';
                     }
                     obj.id=data.chilled_water_pump_state[i].object_id;
                     Shebei.lengdong.push(obj);
                }

             for(var i=0;i<data.cooling_pump_state.length;i++)
                {
                     var obj = new Object();
                     if(data.cooling_pump_state[i].state=="1")
                     {
                         obj.img = 'lengqueshui1.png';
                     }else if(data.cooling_pump_state[i].state=="-1")
                     {
                         obj.img = 'lengqueshui2.png';
                     }else if(data.cooling_pump_state[i].state=="0")
                     {
                        obj.img = 'lengqueshui3.png';
                     }
                     obj.id=data.cooling_pump_state[i].object_id;
                     Shebei.lengque.push(obj);
                }

             for(var i=0;i<data.chiller_state.length;i++)
                {

                     var obj = new Object();
                     if(data.chiller_state[i].state=="1")
                     {
                         obj.img = 'lengrezhuji1.png';
                     }else if(data.chiller_state[i].state=="-1")
                     {
                         obj.img = 'lengrezhuji2.png';
                     }else if(data.chiller_state[i].state=="0")
                     {
                        obj.img = 'lengrezhuji3.png';
                     }
                     obj.id=data.chiller_state[i].object_id;
                     Shebei.reji.push(obj);
                }
            }
       Shebei.taIds = Shebei.ta[0].id+','+Shebei.ta[1].id+','+Shebei.ta[2].id; 
       Shebei.lengdongIds =  Shebei.lengdong[0].id+','+Shebei.lengdong[1].id+','+Shebei.lengdong[2].id+','+Shebei.lengdong[3].id;
       Shebei.lengqueIds =  Shebei.lengque[0].id+','+Shebei.lengque[1].id+','+Shebei.lengque[2].id+','+Shebei.lengque[3].id; 
       Shebei.rejiIds = Shebei.reji[0].id+','+Shebei.reji[1].id+','+Shebei.reji[2].id;      
        }

     Shebei.test=function(type,index,ids,projectid){

           var ds = parseInt(projectid);
        client.openCold(type,index,ids,ds);
     }
	}]);
})();
